using Eno.Application.Dto;
using Eno.Application.Services;
using Eno.Domain.Entity.App;
using Eno.Infrastructure.Tools;
using Microsoft.AspNetCore.Mvc;

namespace Eno.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
public class DepartmentController : ControllerBase
{
    private readonly DepartmentService _service;

    public DepartmentController(DepartmentService departmentService)
    {
        _service = departmentService;
    }

    [HttpGet]
    public async Task<IActionResult> GetDepartmentAsync()
    {
        try
        {
            var result = await _service.GetDepartmentAsync();
            return Ok(result); 
        }
        catch (Exception)
        {
            // 可选：记录日志 ex
            return Ok(Tips<object>.Fail("获取部门列表失败"));
        }
    }

    [HttpPost]
    public async Task<IActionResult> AdditonDepartmentAsync(DepartmentDto departmentDto)
    {
        return Ok(await _service.AdditionDepartmentAsync(departmentDto));
    }

    [HttpDelete("{departmentId}")]
    public async Task<IActionResult> DeleteDepartmentAsync(Guid departmentId)
    {
        return Ok(await _service.DeleteDepartmentAsync(departmentId));

    }

    [HttpPut("{departmentId}")]
    public async Task<IActionResult> UpdateDepartmentAsync(Guid departmentId, DepartmentDto departmentDto)
    {
        return Ok(await _service.UpdateDepartmentAsync(departmentId, departmentDto));
    }

    [HttpGet("{departmentId}")]
    public async Task<IActionResult> GEtDepartmentByIdAsync(Guid departmentId)
    {
        return Ok(await _service.GetAppDepartmentByIdAsync(departmentId));
    }

    [HttpPatch("{departmentId}/toggle-status")]
    public async Task<IActionResult> ToggleDepartmentStatusAsync(Guid departmentId)
    {
        return Ok(await _service.ToggleDepartmentStatusAsync(departmentId));
    }

}